#!/usr/bin/env bash

BASE_DIR=$(pwd)
CONFIG_FILE=${BASE_DIR}/runner.cfg
DERIVED_DATA_DIR=${BASE_DIR}/derivedData

mkdir build

# mobileprovision 文件会缓存在 ~/Library/MobileDevice/Provisioning\ Profiles

#-------------------build TestRunner1.ipa by xcode14+
rm -rf ~/Library/MobileDevice/Provisioning\ Profiles
rm -rf $DERIVED_DATA_DIR
#CODE_SIGN_IDENTITY = iPhone Developer
#echo "DEVELOPMENT_TEAM = 63RNZU87WM
echo "DEVELOPMENT_TEAM = 347N867749
PRODUCT_BUNDLE_IDENTIFIER = com.testbird.ent.TestRunner" > $CONFIG_FILE
# -arch armv7,arm64
xcodebuild build-for-testing -scheme TestRunner -sdk iphoneos -configuration Release -allowProvisioningUpdates -xcconfig $CONFIG_FILE -derivedDataPath $DERIVED_DATA_DIR
mkdir Payload
mv $DERIVED_DATA_DIR/Build/Products/Release-iphoneos/*.app Payload/
zip -r TestRunner1.ipa Payload
rm -rf $CONFIG_FILE
rm -rf $DERIVED_DATA_DIR
rm -rf Payload
mv TestRunner1.ipa build/